import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, UseGuards } from "@nestjs/common";
import { JwtAuthGuard } from "../modules/auth/guard/jwt-auth.guard";
import { UsersEntity } from "../Entity/user.entity";
import { UsersService } from "../service/users.service";
import { MyController } from "../modules/action/descriptor/http.decorator";
import { MyApi } from "../modules/action/descriptor/function.descriptoor";
@UseGuards(JwtAuthGuard)
@MyController('UsersController')
@Controller('user')
export class UsersController{
    constructor(
        private readonly userService: UsersService,
        
    ){}
   
    @Post()
    @MyApi('添加一条用户信息')
    addUser(@Body() usersEntity: UsersEntity) {
        return this.userService.create(usersEntity);
    }
    
    @Get()
    @MyApi('询所有用户信息')
    async findAll(): Promise<UsersEntity[]> {
        return this.userService.findAll();
    }

    @Get('/username/:username')
    @MyApi('查询某个用户信息')
    async findOne(@Param('username') usernmae: string): Promise<UsersEntity> {
        return this.userService.findOne(usernmae);
    }


    @Delete(':id')
    @MyApi('根据id删除某个用户信息')
    async deleteById(@Param('id', ParseIntPipe) id: number) {
        return this.userService.remove(id);
    }


    @Put()
    @MyApi('修改某个用户信息')
    async updateUser(@Body() usersEntity: UsersEntity) {
        return this.userService.update(usersEntity);
    }



}